package com.example.todolist.controller;


import com.example.todolist.common.CheckLogin;
import com.example.todolist.dto.business.PublishDynamicDTO;
import com.example.todolist.model.Dynamic;
import com.example.todolist.response.BaseResponse;
import com.example.todolist.response.SystemResponse;
import com.example.todolist.service.DynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-02-25
 */
@Api(tags = "动态")
@CrossOrigin
@RestController
@RequestMapping("/dynamic")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DynamicController {

    private final DynamicService dynamicService;

    @CheckLogin
    @ApiOperation("发动态")
    @PostMapping("/publishDynamic")
    public BaseResponse publishDynamic(PublishDynamicDTO dto) {
        return dynamicService.publishDynamic(dto);
    }

    @ApiOperation("获取动态")
    @GetMapping(value = "/selectAllDynamicList")
    public SystemResponse<List<Dynamic>> selectAllDynamicList(){
        return dynamicService.selectAllDynamicList();
    }

    @ApiOperation("根据动态id获取动态详情")
    @GetMapping(value = "/findDynamicById")
    public SystemResponse<List<Dynamic>> findDynamicById(String dynamicId){
        return dynamicService.findDynamicById(dynamicId);
    }

    @CheckLogin
    @ApiOperation("获取个人动态")
    @GetMapping(value = "/personalDynamic")
    public SystemResponse<List<Dynamic>> personalDynamic(){
        return dynamicService.personalDynamic();
    }

    @CheckLogin
    @ApiOperation("删除动态")
    @PostMapping(value = "/deleteDynamic")
    public BaseResponse deleteDynamic(String dynamicId){
        return dynamicService.deleteDynamic(dynamicId);
    }

}

